#ifndef JSON_HELPER_H
#define JSON_HELPER_H

inline
int get_int( json_value * p_json_value ){
	if( p_json_value->type != JSON_INT ){
		printf( "ERROR in get_int: Json_Value is not int type." );
		exit(-1);
	}
	return p_json_value->int_value;
}

inline
unsigned get_unsigned( json_value * p_json_value ){
	if( p_json_value->type == JSON_INT ){
		if( p_json_value->int_value >= 0 )
			return p_json_value->int_value;
	}else if( p_json_value->type == JSON_UINT ){
		return p_json_value->unsigned_value;
	}else{
		printf( "ERROR in get_unsigned: Json_Value is not unsigned type." );
		exit(-1);
	}
}

inline
long int get_long_int( json_value * p_json_value ){

	if( p_json_value->type == JSON_INT ){
		return p_json_value->int_value;
	}else if( p_json_value->type == JSON_UINT ){
		return p_json_value->unsigned_value;
	}else if( p_json_value->type == JSON_LINT ){
		return p_json_value->long_value;
	}else{
		printf( "ERROR in get_long int: Json_Value is not long int type." );
		exit(-1);
	}
}

inline
unsigned long int get_unsigned_long_int( json_value * p_json_value ){
	
	if( p_json_value->type == JSON_INT ){
		if( p_json_value->int_value >= 0 )
			return p_json_value->int_value;
	}else if( p_json_value->type == JSON_UINT ){
		return p_json_value->unsigned_value;
	}else if( p_json_value->type == JSON_LINT ){
		if( p_json_value->long_value >= 0 )
			return p_json_value->long_value;
	}else if( p_json_value->type == JSON_ULINT ){
		return p_json_value->ulong_value;
	}else{
		printf( "ERROR in get_unsigned long int: Json_Value is not unsigned long int type." );
		exit(-1);
	}
}
#endif